#include "topdbs_string.hpp"
#include "topdbs_field.hpp"

namespace topdbs
{
    DBSValue::DBSValue()
        : m_dateType(DBS_dtString)
        , m_string("")
    {
    }

    string DBSValue::toString() const
    {
        string value;
        switch(m_dateType)
        {
        case DBS_dtBool:
            value = topdbs_string::to_string<bool>(m_InternalScalar.m_Bool);
            break;
        case DBS_dtShort:
            value = topdbs_string::to_string<short>(m_InternalScalar.m_Short);
            break; 
        case DBS_dtUShort:
            value = topdbs_string::to_string<unsigned short>(m_InternalScalar.m_uShort);
            break;
        case DBS_dtInt32:
            value = topdbs_string::to_string<int>(m_InternalScalar.m_Int32);
            break;
        case DBS_dtUInt32:
            value = topdbs_string::to_string<unsigned int>(m_InternalScalar.m_uInt32);
            break;
        case DBS_dtLong:
            value = topdbs_string::to_string<long>(m_InternalScalar.m_Long);
            break;         
        case DBS_dtULong:
            value = topdbs_string::to_string<unsigned long>(m_InternalScalar.m_uLong);
            break; 
        case DBS_dtInt64:
            value = topdbs_string::to_string<int64_t>(m_InternalScalar.m_Int64);
            break; 
        case DBS_dtUInt64:
            value = topdbs_string::to_string<uint64_t>(m_InternalScalar.m_uInt64);
            break; 
        case DBS_dtFloat:
            value = topdbs_string::to_string<float>(m_InternalScalar.m_Float);
            break; 
        case DBS_dtDouble:
            value = topdbs_string::to_string<double>(m_InternalScalar.m_Double);
            break; 
        case DBS_dtString:    
        default:
            value = m_string;
            break;			
        }    
        return value;
    }

    DBSDataType_t DBSValue::DataType() const
    {
        return m_dateType;
    }

    bool DBSValue::asBool() const
    {
        return m_InternalScalar.m_Bool;
    }

    short DBSValue::asShort() const
    {
        return m_InternalScalar.m_Short;
    }

    unsigned short DBSValue::asUShort() const
    {
        return m_InternalScalar.m_uShort;
    }

    short DBSValue::asInt() const
    {
        return m_InternalScalar.m_Int32;
    }

    unsigned short DBSValue::asUInt() const
    {
        return m_InternalScalar.m_uInt32;
    }

    long DBSValue::asLong() const
    {
        return m_InternalScalar.m_Long;
    }

    unsigned long DBSValue::asULong() const
    {
        return m_InternalScalar.m_uLong;
    }

    int64_t DBSValue::asInt64() const
    {
        return m_InternalScalar.m_Int64;
    }

    uint64_t DBSValue::asUInt64() const
    {
        return m_InternalScalar.m_uInt64;
    }

    double DBSValue::asDouble() const
    {
        return m_InternalScalar.m_Double;
    }

    float DBSValue::asFloat() const
    {
        return m_InternalScalar.m_Float;
    }

    string DBSValue::asString() const
    {
        return m_string;
    }

    string DBSValue::asText() const
    {
        return m_string;
    }    

    string DBSValue::asBlob() const
    {
        return m_string;
    }    

    string DBSValue::asClob() const
    {
        return m_string;
    }      

    DBSValue& DBSValue::setAsBool(bool value)
    {
        m_dateType = DBS_dtBool;
        m_InternalScalar.m_Bool = value;
        return *this;
    }

    DBSValue& DBSValue::setAsShort(short value) 
    {
        m_dateType = DBS_dtShort;
        m_InternalScalar.m_Short = value;
        return *this;
    }

    DBSValue& DBSValue::setAsUShort(unsigned short value)
    {
        m_dateType = DBS_dtUShort;
        m_InternalScalar.m_uShort = value;
        return *this;
    }

    DBSValue& DBSValue::setAsInt(int value) 
    {
        m_dateType = DBS_dtInt32;
        m_InternalScalar.m_Int32 = value;
        return *this;
    }

    DBSValue& DBSValue::setAsUInt(unsigned int value)
    {
        m_dateType = DBS_dtUInt32;
        m_InternalScalar.m_uInt32 = value;
        return *this;
    }

    DBSValue& DBSValue::setAsLong(long value) 
    {
        m_dateType = DBS_dtLong;
        m_InternalScalar.m_Long = value;
        return *this;
    }

    DBSValue& DBSValue::setAsULong(unsigned long value)
    {
        m_dateType = DBS_dtULong;
        m_InternalScalar.m_uLong = value;
        return *this;
    }

    DBSValue& DBSValue::setAsInt64(int64_t value) 
    {
        m_dateType = DBS_dtInt64;
        m_InternalScalar.m_Int64 = value;
        return *this;
    }

    DBSValue& DBSValue::setAsUInt64(uint64_t value) 
    {
        m_dateType = DBS_dtUInt64;
        m_InternalScalar.m_uInt64 = value;
        return *this;
    }

    DBSValue& DBSValue::setAsDouble(double value) 
    {
        m_dateType = DBS_dtDouble;
        m_InternalScalar.m_Double = value;
        return *this;
    }

    DBSValue& DBSValue::setAsFloat(float value) 
    {
        m_dateType = DBS_dtFloat;
        m_InternalScalar.m_Float = value;
        return *this;
    }

    DBSValue& DBSValue::setAsString(const string& value ) 
    {
        m_dateType = DBS_dtString;
        m_string = value;
        return *this;
    }

    DBSValue& DBSValue::setAsText(const string& value ) 
    {
        m_dateType = DBS_dtText;
        m_string = value;
        return *this;
    }  

    DBSValue& DBSValue::setAsBlob(const string& value ) 
    {
        m_dateType = DBS_dtBLob;
        m_string = value;
        return *this;
    } 

    DBSValue& DBSValue::setAsBlob(const unsigned char* data,size_t data_size) 
    {
        m_dateType = DBS_dtBLob;
        m_string = string((const char*)data,data_size);
        return *this;
    }

    DBSValue& DBSValue::setAsClob(const string& value ) 
    {
        m_dateType = DBS_dtCLob;
        m_string = value;
        return *this;
    }     
}
